﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using mooc.Models;

namespace mooc.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;
        private readonly IProductRepository _repository;
        private readonly IConfiguration _config;
        public string Message { get; set; }
        public List<Product> Products { get; set; }

        public HomeController(ILogger<HomeController> logger, IProductRepository repository, IConfiguration config)
        {
            _logger = logger;
            _repository = repository;
            _config = config;
        }

        public IActionResult Index()
        {
            ViewBag.Message = _config["MESSAGE"] ?? "ASP.NET Core 与Docker";
            Products = _repository.Products.ToList();

            return View(Products);
        }

    
    }
}
